package Operation;

import book.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还书籍");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要归还的书籍:");
        String name = scanner.nextLine();
        int n = bookList.getBooknum();
        int i = 0;
        for (i = 0; i < n; i++) {
            if (name.equals(bookList.getBooks()[i].getName())) {
                //System.out.println("找到了你要的书！");
                if(bookList.getBooks()[i].getBorrower() == true){
                    System.out.println("已经归还请勿重复归还");

                    break;
                }else if (bookList.getBooks()[i].getBorrower() == false){
                    System.out.println("成功归还: " + name);
                    bookList.getBooks()[i].setBorrower(true);
                    break;
                }
            }

        }
        if(i == n){
            System.out.println("对不起，本图书馆暂时没有这本书！，所以还不了！");
        }
    }
}
